package cn.usian.service.impl;

import cn.usian.dao.UserMapper;
import cn.usian.pojo.User;
import cn.usian.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public Page<User> findAll(Map searchMap, Integer pageIndex) {
        LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(searchMap.get("name")!=null,User::getName,searchMap.get("name"));
        queryWrapper.lt(searchMap.get("maxAge")!=null && searchMap.get("maxAge")!="",User::getAge,searchMap.get("maxAge"));
        queryWrapper.gt(searchMap.get("minAge")!=null && searchMap.get("minAge")!="",User::getAge,searchMap.get("minAge"));
        Page<User> page = new Page<>(pageIndex,2);
        return userMapper.selectPage(page,queryWrapper);
       /* page.getCurrent();
        page.getTotal();
        page.getPages()*/
    }

    @Override
    public void add(User user) {
        userMapper.insert(user);
    }

    @Override
    public User findById(String id) {
        return userMapper.selectById(id);
    }

    @Override
    public void update(User user) {
        userMapper.updateById(user);
    }

    @Override
    public void del(String id) {
        userMapper.deleteById(id);
    }
}
